import store from '../store'

/**
 * 将单树形结构/树形结构数组转化成数组扁平化结构
 * @param {Object} treeData 
 */
export const treeToArray = (treeData) => {
  const result = []
  const loop = data => {
    if (data && Array.isArray(data) && data.length > 0) {
      data.forEach(item => {
        loop(item)
      })
    }
    else {
      result.push(data)
      if (data.hasOwnProperty('children')) {
        let children = data.children
        loop(children)
      }
    }
  }
  loop(treeData)
  return result
};